/*
 * 该类用于asyeditor中调动外部命令，包括
 * 1.利用 asy程序将asy文件转换成eps/pdf等
 * 2.利用 gs程序将eps文件转换成png用于预览。
 */
#ifndef ASYPROCESS_H_
#define ASYPROCESS_H_
#include <QObject>
#include <QProcess>
#include <QString>
#include <QStringList>

#define AsyOk 0
#define GsOk	1
#define AsyFailed 2
#define GsFailed 3
#define UnknowFailed 4


class AsyProcess :public QObject
{
	Q_OBJECT
public:
	enum Type{ASY2EPS,ASY2PDF,EPS2PNG,ASY2PNG};
//	enum FinishType{AsyOk,GsOk,AsyFailed,GsFailed,UnkonwFailed};
	AsyProcess(QObject *parent);
	~AsyProcess();

	QString readErrorInfo(); //如果finished(false) ，则在这里读出最后的失败信息

	int asyErrorLineNumber();
	QString asyErrorInfo();

public slots:
	void transform(QString sfile,QString dfile="tmp",Type t=ASY2PNG );
	void loadConfig();

private:
	QProcess *asyProc;
	QProcess *gsProc;
	QString asyPath;
	QString gsPath;
	QStringList asyParms;
	QStringList gsParms;
	QString descBasenmae;
	bool needGS;

	QString failedStr;

private slots:
	void sltAsyFinished(int exitCode,QProcess::ExitStatus exitStatus);
	void sltGsFinished(int exitCode,QProcess::ExitStatus exitStatus);

	void sltAsyError(QProcess::ProcessError err);
	void sltGsError(QProcess::ProcessError err);

signals:
	void finished(int);
	void error(QString info); //QProcess运行外部命令出错
};

#endif /* ASYPROCESS_H_ */
